package com.itlaobing.test;

import java.util.Random;
import java.util.concurrent.*;

public class ThreadTest2 {

    private static class MyThread extends Thread{//继承Thread
        @Override
        public void run() {
//            线程体（需要新创建的线程中执行的任务，可以写在这里）
            for (int i = 0; i <1000 ; i++) {
                System.out.println("副线程"+getName()+"执行："+i);
                if(i%20==0){
//                    try {
//                        Thread.sleep(50);
//                    } catch (InterruptedException e) {
//                        e.printStackTrace();
//                    }
                    yield();
                }
            }
        }
    }

    public static void main(String[] args) {
        MyThread myThread=new MyThread();
        myThread.setName("线程1");
        System.out.println(myThread.getState());
        myThread.setPriority(Thread.NORM_PRIORITY);
        myThread.start();


        MyThread myThread2=new MyThread();
        myThread2.setName("线程2");
        myThread2.setPriority(Thread.MAX_PRIORITY);
        myThread2.start();

        for (int i = 0; i <1000 ; i++) {
//            System.out.println("主线程执行："+i);
        }
        System.out.println(myThread.getState());
    }
}
